﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Interactivity;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Documents;
using System.Windows.Media;

namespace XWord.WPF.Behaviors
{
    public class ListBoxSearchBehavior : Behavior<ListBox>
    {
        protected override void OnAttached()
        {
            AssociatedObject.KeyDown += new KeyEventHandler(AssociatedObject_KeyDown);
            base.OnAttached();
        }

        void AssociatedObject_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            AdornerLayer.GetAdornerLayer(AssociatedObject).Add(new TextBoxAdorner(AssociatedObject));
        }
    }

    public class TextBoxAdorner : Adorner
    {
        private ListBox _element;
        private TextBox _textbox;
        public TextBoxAdorner(ListBox element)
            : base(element)
        {
            _element=element;
            _textbox = new TextBox();
            _textbox.Width = 100;
            _textbox.Text = "xxxxx";
            this.AddVisualChild(_textbox);

        }

        protected override Visual GetVisualChild(int index)
        {
            return _textbox;
        }

        protected override int VisualChildrenCount
        {
            get
            {
                return 1;
            }
        }
    }
}
